﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Helper = NorthwindTests.NorthwindTestHelper;
using Northwind.SL;
namespace NorthwindTests
{
	[TestClass]
	public class UnitTest2
	{
		[TestMethod]
		public void TestMethod1()
		{
			Northwind.SL.Model.Customer c = new Northwind.SL.Model.Customer
			{
				Address = "1700 D St. NW",
				City = "Washington",
				PostalCode = "22201",
				Name = "Hans Passant",
				SecureName = new Northwind.SL.Security.SecureString {  Value = "NoBugz"}
			};
			Assert.AreEqual(true, Helper.CanSerializeDeserialize<Northwind.SL.Model.Customer>(c));
		}

		[TestMethod]
		public void NET_DAL_Convert_to_SL()
		{
			using (Helper.dbconnection)
			{
				Helper.dbconnection.Open();
				var processor = new Northwind.NET.DAL.DbQueryProcessor(Helper.dbconnection);
				var suppliers = processor.Execute<Northwind.NET.Model.Supplier>().ToList();
				for (int i = 0; i < suppliers.Count; i++)
				{
					Northwind.SL.Model.Supplier s2 = ConvertExtension.Convert(suppliers[i]);
				}
				var customers = processor.Execute<Northwind.NET.Model.Customer>().ToList();
				for (int i = 0; i < customers.Count; i++)
				{
					Northwind.SL.Model.Customer c2 = ConvertExtension.Convert(customers[i]);
				}
			}			
		}

		[TestMethod]
		public void NowCanWCFSerialize()
		{
			using (Helper.dbconnection)
			{
				Helper.dbconnection.Open();
				var processor = new Northwind.NET.DAL.DbQueryProcessor(Helper.dbconnection);
				var s = processor.Execute<Northwind.NET.Model.Supplier>().First();
				Northwind.SL.Model.Supplier s2 = ConvertExtension.Convert(s);
				Assert.AreEqual(true, Helper.CanSerializeDeserialize<Northwind.SL.Model.Supplier>(s2));

				var c = processor.Execute<Northwind.NET.Model.Customer>().First();
				Northwind.SL.Model.Customer c2 = ConvertExtension.Convert(c);
				Assert.AreEqual(true, Helper.CanSerializeDeserialize<Northwind.SL.Model.Customer>(c2));

				var p = processor.Execute<Northwind.NET.Model.Product>().First();
				Northwind.SL.Model.Product p2 = ConvertExtension.Convert(p);
				Assert.AreEqual(true, Helper.CanSerializeDeserialize<Northwind.SL.Model.Product>(p2));
			}
		}

	}
}
